﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class News : System.Web.UI.PageEx
{
    private DataSet ds = null;
    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strSelectId = string.Empty;
    //////////qiu//////////////
    protected static string strMenu = string.Empty;
    ///////////////////////////
    protected void Page_Load(object sender, EventArgs e)
    {
        strSelectId = Convert.ToString(Request.QueryString["ClassId"]);
        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }
    private void DataBinds()
    {
        int iSelectId = 0;
        int.TryParse(strSelectId, out iSelectId);
        Model.DbClass dbClass = DalEx.DbClassEx.Select(iSelectId);
        //////////qiu//////////////
        strMenu = "园长工作室";
        if (!string.IsNullOrEmpty(Request.QueryString["ClassId"]))
        {
            if (Request.QueryString["ClassId"].ToString() == "1")
            {
                strMenu = "工作室计划";
            }
            if (Request.QueryString["ClassId"].ToString() == "2")
            {
                strMenu = "活动掠影";
            }
        }
        ///////////////////////////
        if (dbClass != null)
        {
            //////////qiu//////////////
            strMenu = dbClass.CName;
            ///////////////////////////
            lblShowTitle.Text = " > " + dbClass.CName;
            //////////qiu//////////////
            setMeta(dbClass.CName + "--" + strMenu, dbClass.CKeywords, dbClass.CDescription);
            ///////////////////////////
        }

        string strQuery = " and aLang='YuanZhang'";
        if (!string.IsNullOrEmpty(strSelectId))
        {
            strQuery += " and aClassIds like '%|0%|' and AClassId=" + strSelectId + "";
        }
        //if (!string.IsNullOrEmpty(strSelectId))
        //    strQuery += " and aClassIds like '%|" + strSelectId + "%|'";
        ds = WebBase.Comm.SelectByPage("dbArticles ", "*", "aId", strQuery + " and aStatus=1", anpProduct.PageSize, anpProduct.CurrentPageIndex, "aOrder", 0, out iPageCount, out iRecordCount);
        anpProduct.RecordCount = iRecordCount;
        rptNewsList.DataSource = ds;
        rptNewsList.DataBind();

        //int iMaxIndex = this.anpProduct.RecordCount <= this.anpProduct.CurrentPageIndex * this.anpProduct.PageSize ? this.anpProduct.RecordCount : this.anpProduct.CurrentPageIndex * this.anpProduct.PageSize;
        //int iMinIndex = this.anpProduct.CurrentPageIndex <= 1 ? 1 : (this.anpProduct.CurrentPageIndex - 1) * this.anpProduct.PageSize + 1;
        //litShowCustomHtml0.Text = string.Format("当前显示{0}-{1}条共{2}条 每页{3}条", new object[] { 
        //    iMinIndex, 
        //    iMaxIndex, 
        //    this.anpProduct.RecordCount, 
        //    this.anpProduct.PageSize
        //});
        //litShowCustomHtml1.Text = string.Format("当前第{0}/{1}页", new object[] { this.anpProduct.CurrentPageIndex, this.anpProduct.PageCount, this.anpProduct.RecordCount, this.anpProduct.PageSize });
    }
    protected void anpProduct_PageChanged(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void rptClassMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            HyperLink hlLinks = (HyperLink)e.Item.FindControl("hlLinks");
            string strCurrentId = Convert.ToString(drv["Cid"]);
            if (strCurrentId == strSelectId)
                hlLinks.Attributes.Add("class", "on");
        }
    }
    private void setMeta(string title, string key, string des)
    {
        string strWebTitle = string.Empty, strWebKeywords = string.Empty, strWebDescription = string.Empty;
        Model.DbSystem dbSystem = Dal.DbSystemDal.Select(1);
        if (dbSystem != null)
        {
            strWebTitle = dbSystem.STitle;
            strWebKeywords = dbSystem.SKeywords;
            strWebDescription = dbSystem.SDescription;
        }
        HtmlMeta keywords = new HtmlMeta(); // keywords
        HtmlMeta description = new HtmlMeta(); // description
        keywords.Name = "keywords";
        keywords.Content = string.IsNullOrEmpty(key) ? strWebKeywords : key;

        this.Title = string.IsNullOrEmpty(title) ? strWebTitle : title;

        description.Name = "description";
        description.Content = string.IsNullOrEmpty(des) ? strWebDescription : des;

        Page.Header.Controls.Add(keywords);
        Page.Header.Controls.Add(description);
    }
}
